package com.starleague.battletech.unit.jpa.appengine;

import java.util.Map;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

import com.starleague.battletech.unit.IBattletechUnitCriticalSlot;
import com.starleague.jpa.appengine.GaeDao;

@MappedSuperclass
public abstract class BattletechUnitCriticalSlotGae
        extends GaeDao
        // TODO: GaeDaoChild
        implements IBattletechUnitCriticalSlot
{
    @Basic(optional = false)
    @Column(nullable = false)
    private int index;

    @Basic(optional = false)
    @Column(nullable = false)
    private boolean isHit;

    protected BattletechUnitCriticalSlotGae(int index)
    {
        this.index = index;
    }

    protected BattletechUnitCriticalSlotGae()
    {
        //
    }

    public int getIndex()
    {
        return this.index;
    }

    protected void setIndex(int index)
    {
        this.index = index;
    }

    @Override
    public boolean isHit()
    {
        return this.isHit;
    }

    public void setHit(boolean isHit)
    {
        this.isHit = isHit;
    }

    @Transient
    @Override
    public boolean isHittable()
    {
        return (this.getComponent() != null) ? this.getComponent().isHittable() : false;
    }

    @Override
    public Map<String, Object> infoProperties()
    {
        Map<String, Object> infoPropertyMap = super.infoProperties();
        infoPropertyMap.put("index", this.index);
        infoPropertyMap.put("isHit", this.isHit);
        infoPropertyMap.put("isHittable", this.isHittable());
        return infoPropertyMap;
    }
}
